package com.xwh.shop.orders.service.config;

import com.xwh.shop.orders.service.interceptors.AuthorizationInterceptor;
import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Web MVC配置类
 *
 * @author xwh
 * @since 2025-07-02
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    /**
     * 授权拦截器，用于验证JWT令牌
     */
//    注册拦截器
    @Resource
    private AuthorizationInterceptor authorizationInterceptor;

    /**
     * 添加拦截器配置
     * @param registry 拦截器注册表
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authorizationInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(
                        "/**/login",
                        "/doc.html",
                        "/webjars/**",
                        "/swagger-resources/**",
                        "/v3/api-docs/**",
                        "/**/favicon.ico",
                        "/error",
                        "/**/**.json",
                        "/static/**",
                        "/public/**",
                        "/resources/**",
                        "/META-INF/resources/**",
                        "/**/*.html",
                        "/**/*.css",
                        "/**/*.js",
                        "/**/*.png",
                        "/**/*.jpg",
                        "/**/*.jpeg",
                        "/**/*.gif",
                        "/**/*.svg",
                        "/**/*.ico",
                        "/**/*.ttf",
                        "/**/*.woff",
                        "/**/*.woff2",
                        "/**/*.eot");
    }
}
